package com.ztc.ZtcRoutePrice.dao;
import java.util.List;
import org.springframework.stereotype.Repository;

import com.aqgj.util.BaseDaoImpl;
import com.ztc.ZtcRoutePrice.bean.ZtcRoutePrice;
/**
 * <p>
 *
 * </p>
 *
 * @ClassName ZtcRoutePriceDao
 * @JDK 1.5
 * @author
 * @date
 */
@Repository("ZtcRoutePriceDao")
public class ZtcRoutePriceDao extends BaseDaoImpl<ZtcRoutePrice> {
	 public String save(ZtcRoutePrice ztcRoutePrice) {
	        this.getHibernateTemplate().save(ztcRoutePrice);
	        return ztcRoutePrice.getId();
	    }
	    public List<ZtcRoutePrice> getAllZtcRoutePrices() {
	        return this.getAll();
	    }

	    public String delete(String id,String routeId) {
	    	String sql="delete from ztc_route_price where 1=1";
	    	if(id!=null){
	    		sql+=" and id='"+id+"'";
	    	}
	    	if(routeId!=null){
	    		sql+=" and fk_ztc_route_id='"+routeId+"'";
	    	}
	    	if(this.currentSession().createNativeQuery(sql).executeUpdate()>=0){
				return "1";
			}
			return "0";
	    }
	    
	    public List<ZtcRoutePrice> searchInfoEquals(ZtcRoutePrice ztcRoutePrice) {
	        String sql="select * from ztc_route_price where 1=1";
	        if(ztcRoutePrice.getFkRouteStartSiteId()!=null){
	        	sql+=" and fk_route_start_site_id='"+ztcRoutePrice.getFkRouteStartSiteId()+"'";
	        }
	        if(ztcRoutePrice.getFkRouteEndSiteId()!=null){
	        	sql+=" and fk_route_end_site_id='"+ztcRoutePrice.getFkRouteEndSiteId()+"'";
	        }
	        if(ztcRoutePrice.getPrice()!=null){
	        	sql+=" and price='"+ztcRoutePrice.getPrice()+"'";
	        }
	        if(ztcRoutePrice.getDistance()!=null){
	        	sql+=" and distance='"+ztcRoutePrice.getDistance()+"'";
	        }
	        if(ztcRoutePrice.getType()!=null){
	        	sql+=" and type='"+ztcRoutePrice.getType()+"'";
	        }
	        if(ztcRoutePrice.getFkZtcRouteId()!=null){
	        	sql+=" and fk_ztc_route_id='"+ztcRoutePrice.getFkZtcRouteId()+"'";
	        }
	        if(ztcRoutePrice.getId()!=null){
	        	sql+=" and id='"+ztcRoutePrice.getId()+"'";
	        }
	        List<ZtcRoutePrice> list=this.currentSession().createNativeQuery(sql,ZtcRoutePrice.class).getResultList();
	        return list;
	    }
	    
	    public List<ZtcRoutePrice> searchInfoLikes(String routeStartSiteName,String routeEndSiteName) {
	        String sql="select * from ztc_route_price as price,ztc_route_site as start_site,ztc_route_site as end_site"
	                   +" where price.fk_route_start_site_id=start_site.id and price.fk_route_end_site_id=end_site.id";
	        if(routeStartSiteName!=null){
	        	sql+=" and start_site.name like '%"+routeStartSiteName+"%'";
	        }
	        if(routeEndSiteName!=null){
	        	sql+=" and end_site.name like '%"+routeEndSiteName+"%'";
	        }
	        List<ZtcRoutePrice> list=this.currentSession().createNativeQuery(sql,ZtcRoutePrice.class).getResultList();
	        return list;
	    }
}